package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.SpreadArticle;
import com.ruoyi.system.mapper.SpreadArticleMapper;
import com.ruoyi.system.service.SpreadArticleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (SpreadArticle)表服务实现类
 *
 * @author makejava
 * @since 2022-04-29 11:43:41
 */
@Service
public class SpreadArticleServiceImpl implements SpreadArticleService {
    @Resource
    private SpreadArticleMapper spreadArticleMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param articleId 主键
     * @return 实例对象
     */
    @Override
    public SpreadArticle queryById(Long articleId) {
        return this.spreadArticleMapper.queryById(articleId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<SpreadArticle> queryAllByLimit(int offset, int limit) {
        return this.spreadArticleMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param spreadArticle 实例对象
     * @return 实例对象
     */
    @Override
    public SpreadArticle insert(SpreadArticle spreadArticle) {
        this.spreadArticleMapper.insert(spreadArticle);
        return spreadArticle;
    }

    /**
     * 修改数据
     *
     * @param spreadArticle 实例对象
     * @return 实例对象
     */
    @Override
    public SpreadArticle update(SpreadArticle spreadArticle) {
        this.spreadArticleMapper.update(spreadArticle);
        return this.queryById(spreadArticle.getArticleId());
    }

    /**
     * 通过主键删除数据
     *
     * @param articleId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long articleId) {
        return this.spreadArticleMapper.deleteById(articleId) > 0;
    }
}
